const { envList } = require('../../envList');
const app = getApp();
// pages/me/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username:'',
    password:'',
    showUploadTip: false,
  },
  backlogin:function(){
    wx.navigateTo({
      url: '../login/login',
    })
  },
  phonetap:function(){
    wx.showModal({
      title: '客服服务',
      content: '如果需要联系客服，请拨打12345678910',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          console.log('用户点击确定')
        } else {//这里是点击了取消以后
          console.log('用户点击取消')
        }
      }
    })  
  },
  aboutwe:function(){
    wx.navigateTo({
      url: '../we/we',
    })
  },
 
   
  async getUserProfile(e) {
    const res = await wx.getUserProfile({
      desc: '用于完善用户资料',
    });
    console.log(res);
  },
  getUserProfile() {
    wx.getUserProfile({
      desc: '用于获取用户信息',
      success: (res) => {
        const userInfo = res.userInfo;
        userInfo:{
          avatarUrl: "https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"
          gender: 0
          language: ""
          nickName: "真实昵称"
          }
        console.log(userInfo);
        this.setData({
          nickName:userInfo.nickName
        })
        // 可以在这里对用户信息进行进一步的处理，比如存储到本地缓存或者发送到服务器等
      },
      fail: (err) => {
        console.error(err);
        wx.showToast({
          title: '获取用户信息失败，请重试',
        });
      },
    });
  },
/**
   * 获取登录名
   */
  userinformation: function (e) {
    wx.cloud.database().collection('user')
    .where({})
    .get()
    .then((res) => {
       console.log('请求成功', res.data);
       if (res.data.length === 0) {
         wx.showModal({
           title: '登录失败',
           content: '数据库匹配失败'
         });
       } else {
         console.log('111');
         this.setData({
           name:  res.data.name,
           phone: res.data.mobile,
         });
         console.log('111');
       }
     })
    .catch((err) => {
       console.log('请求失败', err);
       wx.showToast({
         title: "请求失败：" + err.message,
       });
     });
  }

});
